package cn.lds.j375.healthexam.convert;

import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class DateConvert implements Converter<String, LocalDateTime> {

    private DateTimeFormatter formatter;

    @Override
    public LocalDateTime convert(String source) {

        if (StringUtils.isAllBlank(source)){
            return null;
        }

        formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");

        LocalDateTime localDateTime = LocalDateTime.parse(source, formatter);

        return localDateTime;
    }
}
